#include "StdAfx.h"
#include "fast_trigonometries.h"

const double kSin[361] = \
{
  0             ,
  0.017452406437,
  0.034899496703,
  0.052335956243,
  0.069756473744,
  0.087155742748,
  0.104528463268,
  0.121869343405,
  0.139173100960,
  0.156434465040,
  0.173648177667,
  0.190808995377,
  0.207911690818,
  0.224951054344,
  0.241921895600,
  0.258819045103,
  0.275637355817,
  0.292371704723,
  0.309016994375,
  0.325568154457,
  0.342020143326,
  0.358367949545,
  0.374606593416,
  0.390731128489,
  0.406736643076,
  0.422618261741,
  0.438371146789,
  0.453990499740,
  0.469471562786,
  0.484809620246,
  0.500000000000,
  0.515038074910,
  0.529919264233,
  0.544639035015,
  0.559192903471,
  0.573576436351,
  0.587785252292,
  0.601815023152,
  0.615661475326,
  0.629320391050,
  0.642787609687,
  0.656059028991,
  0.669130606359,
  0.681998360062,
  0.694658370459,
  0.707106781187,
  0.719339800339,
  0.731353701619,
  0.743144825477,
  0.754709580223,
  0.766044443119,
  0.777145961457,
  0.788010753607,
  0.798635510047,
  0.809016994375,
  0.819152044289,
  0.829037572555,
  0.838670567945,
  0.848048096156,
  0.857167300702,
  0.866025403784,
  0.874619707139,
  0.882947592859,
  0.891006524188,
  0.898794046299,
  0.906307787037,
  0.913545457643,
  0.920504853452,
  0.927183854567,
  0.933580426497,
  0.939692620786,
  0.945518575599,
  0.951056516295,
  0.956304755963,
  0.961261695938,
  0.965925826289,
  0.970295726276,
  0.974370064785,
  0.978147600734,
  0.981627183448,
  0.984807753012,
  0.987688340595,
  0.990268068742,
  0.992546151641,
  0.994521895368,
  0.996194698092,
  0.99756405026 ,
  0.998629534755,
  0.999390827019,
  0.999847695156,
  1             ,
  0.999847695156,
  0.999390827019,
  0.998629534755,
  0.99756405026 ,
  0.996194698092,
  0.994521895368,
  0.992546151641,
  0.990268068742,
  0.987688340595,
  0.984807753012,
  0.981627183448,
  0.978147600734,
  0.974370064785,
  0.970295726276,
  0.965925826289,
  0.961261695938,
  0.956304755963,
  0.951056516295,
  0.945518575599,
  0.939692620786,
  0.933580426497,
  0.927183854567,
  0.920504853452,
  0.913545457643,
  0.906307787037,
  0.898794046299,
  0.891006524188,
  0.882947592859,
  0.874619707139,
  0.866025403784,
  0.857167300702,
  0.848048096156,
  0.838670567945,
  0.829037572555,
  0.819152044289,
  0.809016994375,
  0.798635510047,
  0.788010753607,
  0.777145961457,
  0.766044443119,
  0.754709580223,
  0.743144825477,
  0.731353701619,
  0.719339800339,
  0.707106781187,
  0.694658370459,
  0.681998360062,
  0.669130606359,
  0.656059028991,
  0.642787609687,
  0.62932039105 ,
  0.615661475326,
  0.601815023152,
  0.587785252292,
  0.573576436351,
  0.559192903471,
  0.544639035015,
  0.529919264233,
  0.51503807491 ,
  0.5           ,
  0.484809620246,
  0.469471562786,
  0.45399049974 ,
  0.438371146789,
  0.422618261741,
  0.406736643076,
  0.390731128489,
  0.374606593416,
  0.358367949545,
  0.342020143326,
  0.325568154457,
  0.309016994375,
  0.292371704723,
  0.275637355817,
  0.258819045103,
  0.2419218956  ,
  0.224951054344,
  0.207911690818,
  0.190808995377,
  0.173648177667,
  0.15643446504 ,
  0.13917310096 ,
  0.121869343405,
  0.104528463268,
  0.0871557427477,
  0.0697564737441,
  0.0523359562429,
  0.0348994967025,
  0.0174524064373,
  0              ,
  -0.0174524064373,
  -0.0348994967025,
  -0.052335956243,
  -0.0697564737441,
  -0.0871557427477,
  -0.104528463268,
  -0.121869343405,
  -0.13917310096,
  -0.15643446504,
  -0.173648177667,
  -0.190808995377,
  -0.207911690818,
  -0.224951054344,
  -0.2419218956,
  -0.258819045103,
  -0.275637355817,
  -0.292371704723,
  -0.309016994375,
  -0.325568154457,
  -0.342020143326,
  -0.358367949545,
  -0.374606593416,
  -0.390731128489,
  -0.406736643076,
  -0.422618261741,
  -0.438371146789,
  -0.45399049974,
  -0.469471562786,
  -0.484809620246,
  -0.5           ,
  -0.51503807491,
  -0.529919264233,
  -0.544639035015,
  -0.559192903471,
  -0.573576436351,
  -0.587785252292,
  -0.601815023152,
  -0.615661475326,
  -0.62932039105,
  -0.642787609687,
  -0.656059028991,
  -0.669130606359,
  -0.681998360063,
  -0.694658370459,
  -0.707106781187,
  -0.719339800339,
  -0.731353701619,
  -0.743144825477,
  -0.754709580223,
  -0.766044443119,
  -0.777145961457,
  -0.788010753607,
  -0.798635510047,
  -0.809016994375,
  -0.819152044289,
  -0.829037572555,
  -0.838670567945,
  -0.848048096156,
  -0.857167300702,
  -0.866025403784,
  -0.874619707139,
  -0.882947592859,
  -0.891006524188,
  -0.898794046299,
  -0.906307787037,
  -0.913545457643,
  -0.920504853452,
  -0.927183854567,
  -0.933580426497,
  -0.939692620786,
  -0.945518575599,
  -0.951056516295,
  -0.956304755963,
  -0.961261695938,
  -0.965925826289,
  -0.970295726276,
  -0.974370064785,
  -0.978147600734,
  -0.981627183448,
  -0.984807753012,
  -0.987688340595,
  -0.990268068742,
  -0.992546151641,
  -0.994521895368,
  -0.996194698092,
  -0.99756405026,
  -0.998629534755,
  -0.999390827019,
  -0.999847695156,
  -1             ,
  -0.999847695156,
  -0.999390827019,
  -0.998629534755,
  -0.99756405026,
  -0.996194698092,
  -0.994521895368,
  -0.992546151641,
  -0.990268068742,
  -0.987688340595,
  -0.984807753012,
  -0.981627183448,
  -0.978147600734,
  -0.974370064785,
  -0.970295726276,
  -0.965925826289,
  -0.961261695938,
  -0.956304755963,
  -0.951056516295,
  -0.945518575599,
  -0.939692620786,
  -0.933580426497,
  -0.927183854567,
  -0.920504853452,
  -0.913545457643,
  -0.906307787037,
  -0.898794046299,
  -0.891006524188,
  -0.882947592859,
  -0.874619707139,
  -0.866025403784,
  -0.857167300702,
  -0.848048096156,
  -0.838670567945,
  -0.829037572555,
  -0.819152044289,
  -0.809016994375,
  -0.798635510047,
  -0.788010753607,
  -0.777145961457,
  -0.766044443119,
  -0.754709580223,
  -0.743144825477,
  -0.731353701619,
  -0.719339800339,
  -0.707106781187,
  -0.694658370459,
  -0.681998360062,
  -0.669130606359,
  -0.65605902899,
  -0.642787609687,
  -0.62932039105,
  -0.615661475326,
  -0.601815023152,
  -0.587785252292,
  -0.573576436351,
  -0.559192903471,
  -0.544639035015,
  -0.529919264233,
  -0.51503807491,
  -0.5          ,
  -0.484809620246,
  -0.469471562786,
  -0.45399049974,
  -0.438371146789,
  -0.422618261741,
  -0.406736643076,
  -0.390731128489,
  -0.374606593416,
  -0.358367949545,
  -0.342020143326,
  -0.325568154457,
  -0.309016994375,
  -0.292371704723,
  -0.275637355817,
  -0.258819045103,
  -0.2419218956,
  -0.224951054344,
  -0.207911690818,
  -0.190808995377,
  -0.173648177667,
  -0.15643446504,
  -0.13917310096,
  -0.121869343405,
  -0.104528463268,
  -0.0871557427476,
  -0.0697564737441,
  -0.0523359562429,
  -0.0348994967025,
  -0.0174524064373,
  0,
};

const double kCos[361] = \
{
  1           ,
  0.999847695156,
  0.999390827019,
  0.998629534755,
  0.99756405026,
  0.996194698092,
  0.994521895368,
  0.992546151641,
  0.990268068742,
  0.987688340595,
  0.984807753012,
  0.981627183448,
  0.978147600734,
  0.974370064785,
  0.970295726276,
  0.965925826289,
  0.961261695938,
  0.956304755963,
  0.951056516295,
  0.945518575599,
  0.939692620786,
  0.933580426497,
  0.927183854567,
  0.920504853452,
  0.913545457643,
  0.906307787037,
  0.898794046299,
  0.891006524188,
  0.882947592859,
  0.874619707139,
  0.866025403784,
  0.857167300702,
  0.848048096156,
  0.838670567945,
  0.829037572555,
  0.819152044289,
  0.809016994375,
  0.798635510047,
  0.788010753607,
  0.777145961457,
  0.766044443119,
  0.754709580223,
  0.743144825477,
  0.731353701619,
  0.719339800339,
  0.707106781187,
  0.694658370459,
  0.681998360062,
  0.669130606359,
  0.656059028991,
  0.642787609687,
  0.62932039105,
  0.615661475326,
  0.601815023152,
  0.587785252292,
  0.573576436351,
  0.559192903471,
  0.544639035015,
  0.529919264233,
  0.51503807491,
  0.5         ,
  0.484809620246,
  0.469471562786,
  0.45399049974,
  0.438371146789,
  0.422618261741,
  0.406736643076,
  0.390731128489,
  0.374606593416,
  0.358367949545,
  0.342020143326,
  0.325568154457,
  0.309016994375,
  0.292371704723,
  0.275637355817,
  0.258819045103,
  0.2419218956,
  0.224951054344,
  0.207911690818,
  0.190808995377,
  0.173648177667,
  0.15643446504,
  0.13917310096,
  0.121869343405,
  0.104528463268,
  0.0871557427477,
  0.0697564737441,
  0.0523359562429,
  0.0348994967025,
  0.0174524064373,
  0              ,
  -0.0174524064373,
  -0.0348994967025,
  -0.0523359562429,
  -0.0697564737441,
  -0.0871557427477,
  -0.104528463268,
  -0.121869343405,
  -0.13917310096,
  -0.15643446504,
  -0.173648177667,
  -0.190808995377,
  -0.207911690818,
  -0.224951054344,
  -0.2419218956,
  -0.258819045103,
  -0.275637355817,
  -0.292371704723,
  -0.309016994375,
  -0.325568154457,
  -0.342020143326,
  -0.358367949545,
  -0.374606593416,
  -0.390731128489,
  -0.406736643076,
  -0.422618261741,
  -0.438371146789,
  -0.45399049974,
  -0.469471562786,
  -0.484809620246,
  -0.5        ,
  -0.51503807491,
  -0.529919264233,
  -0.544639035015,
  -0.559192903471,
  -0.573576436351,
  -0.587785252292,
  -0.601815023152,
  -0.615661475326,
  -0.62932039105,
  -0.642787609687,
  -0.656059028991,
  -0.669130606359,
  -0.681998360063,
  -0.694658370459,
  -0.707106781187,
  -0.719339800339,
  -0.731353701619,
  -0.743144825477,
  -0.754709580223,
  -0.766044443119,
  -0.777145961457,
  -0.788010753607,
  -0.798635510047,
  -0.809016994375,
  -0.819152044289,
  -0.829037572555,
  -0.838670567945,
  -0.848048096156,
  -0.857167300702,
  -0.866025403784,
  -0.874619707139,
  -0.882947592859,
  -0.891006524188,
  -0.898794046299,
  -0.906307787037,
  -0.913545457643,
  -0.920504853452,
  -0.927183854567,
  -0.933580426497,
  -0.939692620786,
  -0.945518575599,
  -0.951056516295,
  -0.956304755963,
  -0.961261695938,
  -0.965925826289,
  -0.970295726276,
  -0.974370064785,
  -0.978147600734,
  -0.981627183448,
  -0.984807753012,
  -0.987688340595,
  -0.990268068742,
  -0.992546151641,
  -0.994521895368,
  -0.996194698092,
  -0.99756405026,
  -0.998629534755,
  -0.999390827019,
  -0.999847695156,
  -1          ,
  -0.999847695156,
  -0.999390827019,
  -0.998629534755,
  -0.99756405026,
  -0.996194698092,
  -0.994521895368,
  -0.992546151641,
  -0.990268068742,
  -0.987688340595,
  -0.984807753012,
  -0.981627183448,
  -0.978147600734,
  -0.974370064785,
  -0.970295726276,
  -0.965925826289,
  -0.961261695938,
  -0.956304755963,
  -0.951056516295,
  -0.945518575599,
  -0.939692620786,
  -0.933580426497,
  -0.927183854567,
  -0.920504853452,
  -0.913545457643,
  -0.906307787037,
  -0.898794046299,
  -0.891006524188,
  -0.882947592859,
  -0.874619707139,
  -0.866025403784,
  -0.857167300702,
  -0.848048096156,
  -0.838670567945,
  -0.829037572555,
  -0.819152044289,
  -0.809016994375,
  -0.798635510047,
  -0.788010753607,
  -0.777145961457,
  -0.766044443119,
  -0.754709580223,
  -0.743144825477,
  -0.731353701619,
  -0.719339800339,
  -0.707106781187,
  -0.694658370459,
  -0.681998360062,
  -0.669130606359,
  -0.656059028991,
  -0.642787609687,
  -0.62932039105,
  -0.615661475326,
  -0.601815023152,
  -0.587785252292,
  -0.573576436351,
  -0.559192903471,
  -0.544639035015,
  -0.529919264233,
  -0.51503807491,
  -0.5        ,
  -0.484809620246,
  -0.469471562786,
  -0.45399049974,
  -0.438371146789,
  -0.422618261741,
  -0.406736643076,
  -0.390731128489,
  -0.374606593416,
  -0.358367949545,
  -0.342020143326,
  -0.325568154457,
  -0.309016994375,
  -0.292371704723,
  -0.275637355817,
  -0.258819045103,
  -0.2419218956,
  -0.224951054344,
  -0.207911690818,
  -0.190808995377,
  -0.173648177667,
  -0.15643446504,
  -0.13917310096,
  -0.121869343405,
  -0.104528463268,
  -0.0871557427476,
  -0.0697564737441,
  -0.0523359562429,
  -0.0348994967025,
  -0.0174524064373,
  0               ,
  0.0174524064373,
  0.0348994967025,
  0.052335956243,
  0.0697564737441,
  0.0871557427477,
  0.104528463268,
  0.121869343405,
  0.13917310096,
  0.15643446504,
  0.173648177667,
  0.190808995377,
  0.207911690818,
  0.224951054344,
  0.2419218956,
  0.258819045103,
  0.275637355817,
  0.292371704723,
  0.309016994375,
  0.325568154457,
  0.342020143326,
  0.358367949545,
  0.374606593416,
  0.390731128489,
  0.406736643076,
  0.422618261741,
  0.438371146789,
  0.45399049974,
  0.469471562786,
  0.484809620246,
  0.5           ,
  0.51503807491 ,
  0.529919264233,
  0.544639035015,
  0.559192903471,
  0.573576436351,
  0.587785252292,
  0.601815023152,
  0.615661475326,
  0.62932039105,
  0.642787609687,
  0.656059028991,
  0.669130606359,
  0.681998360063,
  0.694658370459,
  0.707106781187,
  0.719339800339,
  0.731353701619,
  0.743144825477,
  0.754709580223,
  0.766044443119,
  0.777145961457,
  0.788010753607,
  0.798635510047,
  0.809016994375,
  0.819152044289,
  0.829037572555,
  0.838670567945,
  0.848048096156,
  0.857167300702,
  0.866025403784,
  0.874619707139,
  0.882947592859,
  0.891006524188,
  0.898794046299,
  0.906307787037,
  0.913545457643,
  0.920504853452,
  0.927183854567,
  0.933580426497,
  0.939692620786,
  0.945518575599,
  0.951056516295,
  0.956304755963,
  0.961261695938,
  0.965925826289,
  0.970295726276,
  0.974370064785,
  0.978147600734,
  0.981627183448,
  0.984807753012,
  0.987688340595,
  0.990268068742,
  0.992546151641,
  0.994521895368,
  0.996194698092,
  0.99756405026,
  0.998629534755,
  0.999390827019,
  0.999847695156,
  1             ,
};

const double angle_math::kPi        = 3.1415926535898;
const double angle_math::kRadian		= 180/kPi;
const double angle_math::kInvRadian = kPi/180.0;

const double simple_math::kGolden	  = 0.6180339887499;
const double simple_math::kGoldenC  = 1 - kGolden;
const double simple_math::kSqrt2	  = 1.4142135623731;
const double simple_math::kInvSqrt2 = 0.7071067811865;

bool angle_math::contain(int a, int s, int e)
{
  if (e > s) {
    return a>=s && a<=e;
  } else if (s > e) {
    return a>=s || a<=e;
  } else {
    return a==s;
  }
}

double angle_math::normalize(double x)
{
  double  y = fmod(x, 360.0);
  if (y < 0.0) {
    y += 360.0;
  }

  return y;
}


bool idegree::contain(int start_angle, int end_angle) const
{
  return angle_math::contain(val, start_angle, end_angle);
}
